/**
 * file: cms_public.js
 * create: 2013-01-14
 * author: yanghzheng@evmtv.com
 *
*/

// Classes
Namespace.register( 'com.evmtv.cms' );
com.evmtv.cms.Global = function()
{
	this.version = '1.0';
}

com.evmtv.cms.Global.prototype =
{
	eventListener:
	{
		items: [],

		addListener: function( F )
		{
			this.items.push( F );
			return this;
		}

		,dispatchEvent: function( E )
		{
			for( var i in this.items )
			{
				if( !this.items[i]( E )) return false;
			}
		}
	}
}

// Globals
var $G_InitRoution = [];
var $G = 0;

function CMS_PageLoad()
{
	
	$G = new com.evmtv.cms.Global();

	if( $G_InitRoution )
	{
		for( var i in $G_InitRoution )
		{
			if( $G_InitRoution[i] ) $G_InitRoution[i]();
		}
	}
	var next = document.getElementById("CMS_ContentPager_Next");
	var back = document.getElementById("xComp38928");
	if(next){
		next.focus();
	}else if(back){
		back.focus();
		back.setAttribute("autofocus", "autofocus");
	}
	document.onkeydown = CMS_PageKeydown;
	posterCtrl();
	//mobileMc.overwrite();
	document.onkeydown = evm_cms_domCtrl.trackKey;
	evm_cms_domCtrl.marquee_replace();
}

function posterCtrl(){
	var IO = document.getElementsByTagName("img");
	if(IO){
		for(var i = 0,len = IO.length;i < len;i++){
			if(IO[i].getAttribute('CMS_Class') == 'CmsComp_Image_Static'){
				if(poster_img)
					IO[i].src = poster_img;
				break;
			}
		}
	}
}

function CMS_PageKeydown( E )
{
	E = E || window.event;
	$G.eventListener.dispatchEvent( E );
}


///
function getOldUrl(){
   var oldUrlStr = window.location.href;
       oldUrlStr = oldUrlStr.substring(oldUrlStr.indexOf("oldUrl=")+7,oldUrlStr.length);
	   alert(oldUrlStr);
   return oldUrlStr;
}


var CMS_CompCtrl =
{
	//滚动控制
	scrollCtrl: function( S, A )
	{
		try
		{
			var M = document.documentElement.getElementsByTagName("marquee");
			if(S.innerHTML == '停止播放'){
		    	   M.start();
		     	   S.innerHTML = '开始播放';
		     }else{
		    	   M.stop();
		     	   S.innerHTML = '开始播放';
		     }
//			S.scrollState = 1 - S.scrollState;
//			alert(S.assocComp);
//			if( S.scrollState )
//			{
//				$(S.assocComp).start();
//				S.innerHTML = 'ͣ停止滚动';
//			}
//			else
//			{
//				$(S.assocComp).stop();
//				S.innerHTML = '开始滚动';
//			}
		}
		catch( E )
		{
			alert(E.message);
		}
	}
}